package tmproject.hlhj.fhp.tmvote.module

import android.content.Context
import com.example.mymvp.BaseModule
import com.lzy.okgo.model.Response
import tmproject.hlhj.fhp.tmvote.beans.BaseBean
import tmproject.hlhj.fhp.tmvote.beans.SignUpRuleBean
import tmproject.hlhj.fhp.tmvote.network.Apis
import tmproject.hlhj.fhp.tmvote.network.BaseObersever
import tmproject.hlhj.fhp.tmvote.network.LoadingAction
import java.io.File

/**
 * Created by Never Fear   on 2018\8\7 0007.
Never More....
 */
class SignUpModule :BaseModule {
    var listener:OnSignUpListener?=null

  fun getRuleData(){
      val baseBean = SignUpRuleBean()
    listener?.onSignUpRuleResp(baseBean)
  }

    fun signUp(user_id:String,competitor_name:String,phone:String,profile:String,activity_id:String,
               pay_way:String?,avatar: File,context: Context){
        Apis.signUp(user_id,competitor_name, phone, profile, activity_id, pay_way, avatar)?.let {
            it
                    .doOnSubscribe(LoadingAction(context))
                    .subscribe(object :BaseObersever<Response<BaseBean>>(context){
                override fun onRespSuccess(t: Response<BaseBean>) {
                    val body = t.body()
                    listener?.onSignUpResp(body)
                }

            })
        }
    }

    interface OnSignUpListener{
        fun onSignUpResp(baseBean: BaseBean)
        fun onSignAgain(baseBean: BaseBean)
        fun onSignUpRuleResp(signUpRuleBean: SignUpRuleBean)
    }
}